/**
 * 
 */
package com.brewdroid.pdf;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import android.os.Environment;

import com.brewdroid.model.Recipe;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

/**
 * @author meeusen
 *
 */
public class PDFUtil {
	
	private static Font titleFont = new Font(Font.FontFamily.TIMES_ROMAN,22,Font.BOLD);

	public String createPDF(Recipe r)
	{
		Document document = new Document();
		String filePath = Environment.getExternalStorageDirectory().getPath()+"/"+r.getName()+".pdf";
		try {
			
			//check to see if pdf exists already, if it does delete it and create it new
			File pdf = new File(filePath);
			if(pdf.exists())
				pdf.delete();
			
			PdfWriter.getInstance(document, new FileOutputStream(filePath));
			document.open();
			
			Paragraph p1 = new Paragraph(r.getName(),titleFont);
			Paragraph p3 = new Paragraph(r.toString());
			document.add(p1);
			document.add(p3);
			document.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return filePath;
	}
	
}
